package com.llbnk.common.exception;

import com.llbnk.common.result.ResponseEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author shkstart
 * @create 2022-04-08 13:31
 */
//针对UnifiedExceptionHandler中andleException(Exception e)适用于所有方法的异常处理当出现异常并不知道哪里有问题
//针对UnifiedExceptionHandler中handleException(BadSqlGrammarException e)的特殊方法进行详细说明，有那么多异常不可能写的完
//使用自定义异常来处理各种异常情况 自定义异常前提就是是继承运行时类异常
@Data
@NoArgsConstructor
public class BusinessException extends RuntimeException{
    //错误码
    private  Integer code;
    //错误消息
    private String message;
    /**
     *
     * @param message 错误消息
     */
    public BusinessException(String message) {
        this.message = message;
    }

    /**
     *
     * @param message 错误消息
     * @param code 错误码
     */
    public BusinessException(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    /**
     *
     * @param message 错误消息
     * @param code 错误码
     * @param cause 原始异常对象
     */
    public BusinessException(String message, Integer code, Throwable cause) {
        super(cause);
        this.message = message;
        this.code = code;
    }

    /**
     *
     * @param resultCodeEnum 接收枚举类型
     */
    public BusinessException(ResponseEnum resultCodeEnum) {
        this.message = resultCodeEnum.getMessage();
        this.code = resultCodeEnum.getCode();
    }

    /**
     *
     * @param resultCodeEnum 接收枚举类型
     * @param cause 原始异常对象
     */
    public BusinessException(ResponseEnum resultCodeEnum, Throwable cause) {
        super(cause);
        this.message = resultCodeEnum.getMessage();
        this.code = resultCodeEnum.getCode();
    }

}
